package by.jtraining.london.web;

import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;

import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Scopes;
import com.google.inject.persist.PersistFilter;
import com.google.inject.persist.jpa.JpaPersistModule;
//import com.google.inject.persist.jpa.JpaPersistModule;
import com.google.inject.servlet.GuiceServletContextListener;
import com.google.inject.servlet.ServletModule;
import com.google.inject.struts2.Struts2GuicePluginModule;

public final class GuiceServletConfigInitializer extends GuiceServletContextListener{

	@Override
	protected Injector getInjector() {
		return Guice.createInjector(
				new WebModule(),
				new JpaPersistModule("LontonTraining"),
				new Struts2GuicePluginModule(),
				new ServletModule(){
					@Override
					protected void configureServlets(){
						filter("/*").through(PersistFilter.class);
						bind(StrutsPrepareAndExecuteFilter.class).in(Scopes.SINGLETON);
						filter("/*").through(StrutsPrepareAndExecuteFilter.class);
				}
		});
	}
}
